package com.air.ota.vo;

import java.util.Arrays;

import com.air.ota.util.HexStringUtil;

public class SZTCancelInitReqTransVO extends SZTBaseReqTransVO {
	
	protected byte keyIndex;
	protected byte[] cardAppSequence;
	protected byte[] cardRandom;
	protected byte[] ewalletTransSequence;
	protected byte[] ewalletRemain;
	protected byte[] amount;
	protected byte   transTypeTag;
	protected byte[] terminalCode;
	protected byte[] lastTransData;
	protected byte[] cardDeposit;
	protected byte[] fee;//费用?什么意思?
	protected byte[] sumDeviceTransFee;
	protected byte[] cardSamId;
	protected byte   cardType;
	
	public SZTCancelInitReqTransVO(byte[] deviceSequence, byte[] sztSequence,String deviceTriggerTime,
			byte[] cardAppSequence,byte[] cardRandom,byte[] ewalletTransSequence,
			byte[] ewalletRemain,byte[] amount,byte   transTypeTag,byte[] terminalCode,
			byte[] lastTransData,byte[] cardDeposit,byte[] fee,byte[] sumDeviceTransFee) 
		throws Exception{
		super(deviceSequence, sztSequence,deviceTriggerTime);
		this.transTypeCode = 0x47;
		this.subTransTypeCode = 0x10;
		//this.cardPhyType = 0x02;
		this.tranAppendCode = 0x01;
		
		
		this.keyIndex = 0x01;
		this.cardAppSequence =cardAppSequence;
		this.cardRandom = cardRandom;
		this.ewalletTransSequence = ewalletTransSequence;
		this.ewalletRemain = ewalletRemain;
		this.amount = amount;
		this.transTypeTag = transTypeTag;
		this.terminalCode = terminalCode;
		this.lastTransData = lastTransData;
		this.cardDeposit = cardDeposit;
		this.fee= fee;
		this.sumDeviceTransFee= sumDeviceTransFee;
		
		this.cardSamId = Arrays.copyOfRange(this.samId, 0, 4);
		this.cardType = 0x1C;
		
		this.transData  = makeTransData();
	}
	public byte[] makeTransData(){
		StringBuffer hexStringBuf = new StringBuffer();
		
		hexStringBuf.append(HexStringUtil.byteToHexString(keyIndex));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardAppSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardRandom));
		hexStringBuf.append(HexStringUtil.bytesToHexString(ewalletTransSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(ewalletRemain));
		hexStringBuf.append(HexStringUtil.bytesToHexString(amount));
		hexStringBuf.append(HexStringUtil.byteToHexString(transTypeTag));
		hexStringBuf.append(HexStringUtil.bytesToHexString(terminalCode));
		hexStringBuf.append(this.transDate);
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.lastTransData));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.cardDeposit));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.fee));
		hexStringBuf.append(HexStringUtil.bytesToHexString(sumDeviceTransFee));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardSamId));
		hexStringBuf.append(HexStringUtil.byteToHexString(cardType));
		
		return HexStringUtil.hexStringToBytes(hexStringBuf.toString());
	}
}
